package com.dao.redis.imp;

import java.util.concurrent.TimeUnit;

import org.springframework.data.redis.core.ValueOperations;

import com.dao.redis.IRedislLoginVerifyDao;
import com.dao.redis.redisEntity.LoginVerify;

/**
 * 登录验证控操作类
 * 
 * @author 尚业
 *
 */
public class RedisLoginVerfyDaoImp extends AbstractBaseRedisDao<String, LoginVerify> implements IRedislLoginVerifyDao{

	private Long timeout=1000*60*150l;
	public void add( LoginVerify login) {
		ValueOperations<String,LoginVerify>  valueOperations=redisTemplate.opsForValue();
		
		valueOperations.set(login.getToken(), login, timeout, TimeUnit.MILLISECONDS);
//		boolean result = redisTemplate.execute(new RedisCallback<Boolean>() {  
//            public Boolean doInRedis(RedisConnection connection)  
//                    throws DataAccessException {  
//                RedisSerializer<String> serializer = getStringRedisSerializer();
//                Re
//                byte[] token  = serializer.serialize(login.getToken());  
//                byte[] userName = serializer.serialize(login.getUserName());
//                byte[] timestamp=serializer.serialize(login);
//                
//                return connection..setNX(key, name);  
//            }  
//        });  
//		return false;
	}

	public void delete(String token) {
//		ValueOperations<String,LoginVerify>  valueOperations=redisTemplate.opsForValue();
//		valueOperations.
		// TODO Auto-generated method stub
		
	}

	public LoginVerify get(String token) {
		return redisTemplate.opsForValue().get(token);
		// TODO Auto-generated method stub
//		LoginVerify result = redisTemplate.execute(new RedisCallback<LoginVerify>() {  
//            public LoginVerify doInRedis(RedisConnection connection)  
//                    throws DataAccessException {  
//                RedisSerializer<String> serializer = getStringRedisSerializer();  
//                byte[] key = serializer.serialize(token);  
//                byte[] value = connection.get(key);  
//                if (value == null) {  
//                    return null;  
//                }  
//                String name = serializer.deserialize(value);  
////                return new User(keyId, name, null);  
//            }  
//        });  
//        return result; 
	}

}
